<%-- 
    Document   : showVisits
    Created on : 17.11.2013, 19:39:16
    Author     : palo
--%>

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<f:message var="nadpis" key="top.main"/>
<f:message var="welcome" key="welcome"/>

<s:layout-render name="/mainLayout.jsp" nadpis="${nadpis}">
    <s:layout-component name="body">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
        <script type="text/javascript">
            //<![CDATA[
            $(document).ready(function() {
                $('.toggle').hide();
                var global;
                $('.toggler').click(function() {
                    var target = this.id + '_content';
                    if (global != target) {
                        $('#' + global).hide();
                    }


                    // Use ID-selectors to toggle a single element.
                    $('#' + target).toggle();
                    global = this.id + '_content';

                });

            });
            //]]></script>
            <s:useActionBean beanclass="cz.muni.fi.pa165.mushroom.website.web.VisitActionBean" var="actionBean"/>
            <s:form beanclass="cz.muni.fi.pa165.mushroom.website.web.VisitActionBean">
            <fieldset><legend><f:message key="showVisit.new"/></legend>
                <%@include file="/protected/visitForm.jsp"%>
                <s:submit name="add"><f:message key="showVisit.create"/></s:submit>
                </fieldset>
        </s:form>       

        <h2>
            <f:message key="showVisit.all"/>
        </h2>
        <c:choose>
            <c:when test="${empty actionBean.myVisit}">
                <p><f:message key="visit.list.empty"/></p>
            </c:when>
            <c:otherwise>
                <table class="basic">
                    <tr>
                        <th><f:message key="listVisits.forest"/> </th>
                        <th><f:message key="listVisits.info"/></th>
                        <th><f:message key="listVisits.mushrooms"/></th>                 
                        <th></th>  
                        <th></th>
                    </tr>
                    <c:forEach items="${actionBean.myVisit}" var="visitDto" varStatus="status">   
                        <tr>
                            <td><a class="toggler" id="Forest_${status.count}" ><c:out value="${visitDto.forestDto.name}"/></a></td>
                            <td><c:out value="${visitDto.info}"/></td>
                            <td>
                                <c:forEach items="${visitDto.mushrooms}" var="mushroom">
                                    <c:out value="${mushroom.name}, "/>
                                </c:forEach>    
                            </td>
                            <td class="button"><s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.VisitActionBean" event="delete">
                                    <s:param name="visitDto.id" value="${visitDto.id}"/> 
                                    <s:param name="forestDto.id" value="${visitDto.forestDto.id}"/> 
                                    <s:param name="gathererDto.id" value="${visitDto.gathererDto.id}"/>                             
                                    <f:message key="tab.delete"/>
                                </s:link>
                            </td>
                            <td class="button"><s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.VisitActionBean" event="edit">
                                    <s:param name="visitDto.id" value="${visitDto.id}"/>
                                    <f:message key="tab.edit"/>
                                </s:link>
                            </td>
                        </tr>

                        <tr class="toggle" id="Forest_${status.count}_content">

                            <td colspan="4">
                                <f:message key="listVisits.forestMore"/>:<strong><c:out value="${visitDto.forestDto.name}"/></strong><br />
                        <u><f:message key="showForest.name"/></u>: <c:out value="${visitDto.forestDto.name}"/> <br />
                        <u><f:message key="showForest.description"/></u>: <c:out value="${visitDto.forestDto.description}"/><br />

                    </td>
                </tr>
            </c:forEach> 
        </table>
    </c:otherwise>
</c:choose>

</s:layout-component>
</s:layout-render>
